var express = require('express');
var router = express.Router();
const studentsApi = require("../api/students.js");
router.get('/', async function (req, res, next) {
    // const { curPage, eachPage } = req.query;
    // get里面的参数是{ curPage, eachPage }
    const data = await studentsApi.get();
    res.send(data);
});
router.post('/', async function (req, res, next) {
    const student = req.body;
    console.log(student);
    const data = await studentsApi.add(student);
    res.send(data);
});
router.get('/:id', async function (req, res, next) {
    const { id } = req.params;
    const data = await studentsApi.getById(id);
    res.send(data);
});
// 查看图片
// router.get('/:id', async function (req, res, next) {
//     const { id } = req.params;
//     const data = await studentsApi.getById(id);
//     res.send(data);
// });

router.post('/:_id/imgs/:url', async function (req, res, next) {
    const { _id, url } = req.params;
    await studentsApi.addImg({ _id, url });
    const data = await studentsApi.getById(_id);
    res.send(data);
});

router.delete('/:_id/imgs/:url', async function (req, res, next) {
    const { _id, url } = req.params;
    await studentsApi.deleteImg({ _id, url });
    const data = await studentsApi.getById(_id);
    res.send(data);
});

router.delete('/:id', async function (req, res, next) {
    const { id } = req.params;
    console.log(id,11);
    const data = await studentsApi.deleteStudent(id);
    console.log(data,'ww');
    res.send(data);
});


module.exports = router;
